<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>修改交易密码</title>
<link th:href="@{/ksdH5/css/public/mui/mui.css}" rel="stylesheet"/>
<script th:src="@{/ksdH5/js/public/mui/mui.min.js}"></script>
<script th:src="@{/ksdH5/js/public/jquery.min.js}"></script>
<script th:src="@{/ksdH5/js/public/public.js}"></script>
<link th:href="@{/ksdH5/css/setUp/changeTradingPassword.css}" rel="stylesheet"/>
</head>
<body>
<div class="mui-content">
	<div class="headerBox">
		<a href="javascript:history.go(-1);" class="headerBox_left"><img th:src="@{/ksdH5/img/planList/fanhuiBnt.png}"></a>
		<span>修改交易密码</span>
	</div>
	<div class="changeLoginPassword">
		<div class="changeLoginPassword_inputBox">
			<span>手机号</span>
			<em id="phone" style="font-weight: bold;" th:text="${phone}"></em>
		</div>
		<div class="changeLoginPassword_inputBox1">
			<span>验证码</span>
			<input type="tel" maxlength="6" id="forget_code" placeholder="请输入验证码" />
			<div class="changeLoginPassword_inputBox1_right">
				<a href="javascript:void(0);" class="T-getCode" onclick="sendRegisterCode()">获取验证码</a>
				<em class="T-getCode1"></em>
			</div>
		</div>
		<div class="changeLoginPassword_inputBox">
			<span>交易密码</span>
			<input type="password" id="forget_password1" maxlength="6" placeholder="请输入6位数交易密码" />
		</div>
		<div class="changeLoginPassword_inputBox">
			<span>确认密码</span>
			<input type="password" id="forget_password2" maxlength="6" placeholder="请再次输入交易密码" />
		</div>
	</div>
	<button class="changeLoginPassword_bnt" onclick="resetTransactionPW()">确认</button>
</div>
</body>
<script type="text/javascript">
mui.init({
	swipeBack:true
})
</script>
<script type="text/javascript" th:inline="javascript">
	//获得项目根路径
	var ctx = [[@{/}]];
</script>
<script type="text/javascript">
var prefix=ctx+"h5";
//获取短信验证码
$(function(){
    var validCode=true;
    $(".T-getCode").click (function  () {
        var time=60;
        var $code=$(this);
        if (validCode) {
            validCode=false;
            var t=setInterval(function  () {
                time--;
                $(".T-getCode").hide();
                $(".T-getCode1").show();
                $(".T-getCode1").html(time+"秒");
                if (time==0) {
                    clearInterval(t);
                    $(".T-getCode").html("重新获取");
		            $(".T-getCode1").hide();
                	$(".T-getCode").show();
                    validCode=true;
                }
            },1000)
        }
    })
})

//发送注册验证码
function sendRegisterCode(){
	//判断手机号不为空
	var register_phone = $.trim($("#phone").text());
	var length = register_phone.length;
	var phone=/^1[3456789]\d{9}$/;
	if(length != 11 || !phone.test(register_phone)){
		mui.toast("手机号格式不正确",{ duration:'long'});
		return;
	}
	$.ajax({
		url :prefix +"/sendSMS",
		dataType : "json",
		type : "POST",
		data:{
			"phone":register_phone
		},
		success : function(re) {
			mui.toast(re.msg,{ duration:'long'});
			if(re.status=="out"){
				location.href= prefix + '/login';
			}
			
		}
	});
}


//修改交易密码
function resetTransactionPW(){
	var forget_phone =$.trim($("#phone").text());
	var length = forget_phone.length;
	var phone=/^1[3456789]\d{9}$/;
	if(length != 11 || !phone.test(forget_phone)){
		mui.toast("手机号填写错误",{ duration:'long'});
		return;
	} 
	var password1 = $.trim($("#forget_password1").val());
	if(password1.length<6){
		mui.toast("密码不得小于6位",{ duration:'long'});
		return;
	}
	var password2 = $.trim($("#forget_password2").val());
	if(password1 != password2){
		mui.toast("两次密码不一致",{ duration:'long'});
		return;
	}
	var validate = $.trim($("#forget_code").val());
	if(validate.length<4){
		mui.toast("请输入正确的验证码",{ duration:'long'});
		return;
	}
	$.ajax({
		url : prefix +"/resetTransactionPW",
		dataType : "json",
		type : "POST",
		data:{
			"phone":forget_phone,
			"transPW":password1,
			"validate":validate 
		},
		success : function(re) {
			if(re.status=="out"){
				location.href= prefix + '/login';
			}
			if(re.status=="SUCCESS"){
				mui.toast(re.msg,{ duration:'long'});
				setTimeout(function(){
					window.history.go(-1);
				},3000);
			}else {
				mui.toast(re.msg,{ duration:'long'});
			}
		}
	});
	
}
</script>
</html>
